<script type="text/vm">
    function (vm) {
        require(["common","coAjax","href","eventManager"], function(jSouper,coAjax,href,eventManager) {
            if (location.pathname !== "/sign_in.html") {
                var cb_url = "&cb_url=" + encodeURIComponent(location.href);
                App.set("$Cache.cb_url", cb_url);
            } else {
                App.set("$Cache._in_sign_in_or_up", true);
            }
            //注销功能
            App.set("$Event.user_login_out", function() {
                coAjax.get(appConfig.user.login_out_url,function () {
                    App.set("loginer", null);
                    if (href.isUser()) {
                        location.href="main-beta.html";
                    }
                });
            });

            //获取登陆用户的信息
            /*
             * 管理员相关的页面无需登录
             */
            var no_user_login_pages = {
                "/admin-beta.html": 1,
                "/admin-login.html": 1
            }
            if (no_user_login_pages[location.pathname]) {
                App.set("$Cache.is_in_admin",true);
                return;
            }
            console.log("获取登陆者信息……", location.pathname);
            /*
             * 获取登录者信息
             */
            function _check_collect_bus (collectBus) {
                var is_collect = true;
                if (jSouper.indexOf(collectBus,appConfig.bus_id)===-1) {
                    is_collect = false;
                }
                App.set("$Cache.is_collect_current_bus",is_collect)
            }
            coAjax.get(appConfig.user.loginer, function(data) {
                console.log("登录者信息：", data.result);
                userInfo = data.result;
                App.set("loginer", userInfo);
                //触发相关事件
                eventManager.fire("getLoginer");
                //校验是否已经收藏过此商家
                var collectBus = userInfo.collectBus||[];
                _check_collect_bus(collectBus);
            }, function(errorCode) {
                var muse_login_pages = {
                        "/mobile.personal.html": 1,
                        "/cart-beta.html": 1
                    }
                    //未登录，不可进入个人页，强制跳转到登录页
                if (muse_login_pages[location.pathname]) {
                    location.href="main-beta.html";
                }
                //触发相关事件
                eventManager.reject("getLoginer");
            });

           
            
        });
    }
</script>